<?php
#-------------------#
# @author: ALANKAR 
#-------------------#
/**************************************************/
## Class Name - Model_Reviews (Contains all the functions related to reviews sent to user or sent by user )
## Created By - Techmodi (2/06/2012)
/**************************************************/

class Model_Reviews extends Database 
{	
	## Constructor
	function Model_Reviews() {
		$this->user    = USERS;
		$this->userjobpost = POSTJOB;
		$this->reviews = REVIEWS;
		$this->Database();
	}	

## Function for adding review 
	function addReview($array){
		$this->InsertData($this->reviews,$array,0);
	}

## function for getting review by review id 
	function getReviewById($rid){
		$sql = " SELECT r.*,u.first_name as from_first_name,u.last_name from_last_name,u1.first_name as to_first_name,u1.last_name to_last_name,po.job_desc		         FROM ".$this->reviews." as r 
		       	  LEFT JOIN ".$this->user." as u ON r.from_id = u.id 
			      LEFT JOIN ".$this->user." as u1 ON r.to_id = u1.id 
				  LEFT JOIN ".$this->userjobpost." as po ON r.job_id = po.postjob_id 
				  WHERE r.id = '".$rid."'";
		$res = $this->ExecuteQuery($sql);
		$countRes = $this->FetchRow($res);
		return $countRes;			
	}
	
	## function for getting review by job id 
	function getReviewByJobId($jid){
		$sql = " SELECT r.*,u.first_name as from_first_name,u.last_name from_last_name,u1.first_name as to_first_name,u1.last_name to_last_name,po.job_desc		         FROM ".$this->reviews." as r 
		       	  LEFT JOIN ".$this->user." as u ON r.from_id = u.id 
			      LEFT JOIN ".$this->user." as u1 ON r.to_id = u1.id 
				  LEFT JOIN ".$this->userjobpost." as po ON r.job_id = po.postjob_id 
				  WHERE r.job_id = '".$jid."'";
		$res = $this->ExecuteQuery($sql);
		$countRes = $this->FetchRow($res);
		return $countRes;			
	}

}

?>